<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>人员列表</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    {CSS href="__ADDONSTATIC__css/font.css" /}
    {CSS href="__ADDONSTATIC__css/xadmin.css" /}
    {js href='__ADDONSTATIC__js/jquery-3.2.1.min.js' /}

    {js href='__ADDONSTATIC__js/xadmin.js' /}
    {js href='__ADDONSTATIC__js/util.js' /}
    {js href='__ADDONSTATIC__lib/layui/layui.js' /}
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body" id="page">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" action="{:addonUrl('Project/pagelist')}?page={$page}">
            <input type="text" name="name" placeholder="请输入项目名" autocomplete="off" value="{$name}"
                   class="layui-input">
            <input type="text" name="position" placeholder="请输入坐落位置" autocomplete="off" value="{$position}"
                   class="layui-input">
            <button type="submit" lay-filter="search" lay-submit="" class="layui-btn"><i class="layui-icon">&#xe615;</i>
            </button>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
               href="javascript:location.replace(location.href.slice(0,location.href.indexOf('mid')+5));" title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </form>
    </div>
<xblock>
    <!--<button class="layui-btn" onclick="x_admin_show('添加项目','{:addonUrl('Project/addpage')}')"><i-->
            <!--class="layui-icon"></i>添加-->
    <!--</button>-->
    <button class="layui-btn" onclick="x_admin_show('导入项目','{:addonUrl('Project/importpage')}')"><i class="layui-icon"></i>导入excel</button>
</xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>序号</th>
            <th>项目编号</th>
            <th>项目名称</th>
            <th>项目种类</th>
            <th>客户</th>
            <th>坐落位置</th>
            <th>项目阶段</th>
            <th>项目状态</th>
            <th>截止时间</th>
            <th>操作</th>
        </thead>
        <tbody>
        {volist name='list' id='l'}
        <tr>
            <td>{$i+($page-1)*10}</td>
            <td>{$l.id}</td>
            <td title="{$l.name}" onclick="x_admin_show('项目信息','{:addonUrl('Project/projectInfo')}?projectId={$l.id}')">
                <!--<a title="评价详情" target="_blank" href="{:addonUrl('Project/projectInfo')}?projectId={$l.id}">-->
                {$l.name|subtext=15}
                <!--</a>-->
            </td>
            <td>{$l.type}</td>
            <td>{$l.customer}</td>
            <td>{$l.position}</td>
            <td class="td-stage">{$l.stage}</td>
            <td class="td-status">{$l.status}</td>
            <td>{$l.end_time}</td>
            <td class="td-manage">
                {if condition="$l['status'] == '进行中'"}
                <a class="stage-manage"  title="下一项目阶段"  onclick="changeStage(this,{$l.id})" href="javascript:;">
                    <i class="icon iconfont">&#xe6a6;</i></a>
                {else/}
                <a class="stage-manage"  title="下一项目阶段" style="display: none;"  onclick="changeStage(this,{$l.id})" href="javascript:;">
                    <i class="icon iconfont">&#xe6a6;</i></a>
                {/if}
                
                {if condition="$l['status'] != '结束'"}
                <a class="status-manage" title="状态" onclick="changeStatus(this,{$l.id})"  href="javascript:;">
                    <i class="layui-icon">&#xe601;</i></a>
                {/if}
                <a title="编辑" onclick="x_admin_show('编辑','{:addonUrl('Project/updatepage')}?id={$l.id}')"
                   href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="member_del({$l.id})" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <!--分页页面-->
    <?php echo $list->render() ?>
</div>

<script>
    /**
     * 修改项目状态
     */
    function changeStatus(obj, pid) {
        var statusText = $(obj).parents("tr").find(".td-status").text();
        var data = {};
        if (statusText == '未开始') {
            data.message = "确认开始项目吗？";
            data.status = 1;
        } else if (statusText == "进行中") {
            data.message = "确认结束项目吗？";
            data.status = 2;
        }
        layer.confirm(data.message, function (index) {
            data.id = pid;
            var statusObj = $(obj).parents("tr").find(".td-status");
            var tdmanage = $(obj).parents("tr").find(".td-manage");
            data.changeStatus = true;
            ajaxUrl('{:addonUrl('Project/startProject')}', data, function (res) {
                if (res.code == '1') {
                    if (data.status == '1') {
                        layer.msg('已开始!');
                        statusObj.text("进行中");
                        tdmanage.find(".stage-manage").show();
                    }
                    if (data.status == '2') {
                        layer.msg('已结束!');
                        statusObj.text("结束");
                        tdmanage.find(".status-manage").hide();
                    }
                } else {
                    layer.msg('失败!', {icon: 5, time: 1000});
                }
            })
        });
    }
    /**
     * 修改项目阶段
     */
    function changeStage(obj, pid) {
        var data = {};
        data.pid = pid;
        //项目下一阶段
        ajaxUrl('{:addonUrl('Project/nextStage')}',data,function (res) {
            if (res.code == '1'){
                var stage = res.result;
                if (!stage){
                    layer.msg('已经是最后阶段!');
                    return;
                    console.log("1");
                }
                var nextStageName = stage.name;
                var message = "变更为"+nextStageName+"阶段";
                layer.confirm(message, function () {
                    data.id = pid;
                    data.stage = stage.id;
                    var statusObj = $(obj).parents("tr").find(".td-stage");
                    var tdmanage = $(obj).parents("tr").find(".td-manage");
                    ajaxUrl('{:addonUrl('Project/update')}', data, function (res) {
                        if (res.code == '1') {
                            layer.msg('已变更为'+message+'!');
                            statusObj.text(nextStageName);
                        } else {
                            layer.msg('失败!', {icon: 5, time: 1000});
                        }
                    })
                });
            }else{
                layer.msg('失败!');
            }
        });
    }
    /*用户-删除*/
    function member_del(id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            ajaxUrl('{:addonUrl('Project/delete')}', {id: id}, function (data) {
                console.log(data);
                if (data.code == 1) {
                    layer.msg('已删除!', {icon: 1, time: 1000});
                    location.reload();
                } else {
                    layer.msg(data.message);
                }
            })
        });
    }
</script>
</body>

</html>